package com.example.myapplication.databinding.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.myapplication.bean.User;

public class UserViewModel extends ViewModel {

    public final MutableLiveData<User> mUserLiveData = new MutableLiveData<>();
    int i = 1;

    public UserViewModel() {
        //模拟从网络加载用户信息
        //mUserLiveData.postValue(new User(1, "name1"));
    }

    //模拟 进行一些数据骚操作
    public void doSomething() {
        User user = mUserLiveData.getValue();
        if (user != null) {
            user.age += i;
            user.name = "name" + i;
            i++;
            user.isVisible = i % 2 == 0;
            mUserLiveData.setValue(user);
        }
    }

}

